package 基础篇.线程同步.死锁;

/**
 * @author IBM CHEN ZHI KAN
 * @create 2018/7/28
 */
public class A {
  public synchronized void foo(B b){
    System.out.println(Thread.currentThread().getName()+"进入A实例foo方法");
    try{
      Thread.sleep(1000l);
    } catch (InterruptedException e) {
      e.printStackTrace();
    }
    System.out.println(Thread.currentThread().getName()+"企图调用b实例last方法");
    b.last();
  }
  public synchronized void last(){
    System.out.println("进入A方法内部");
  }
}
class B{
  public synchronized void foo(A a){
    System.out.println(Thread.currentThread().getName()+"进入B实例foo方法");
    try{
      Thread.sleep(1000l);
    } catch (InterruptedException e) {
      e.printStackTrace();
    }
    System.out.println(Thread.currentThread().getName()+"企图调用A实例last方法");
    a.last();
  }
  public synchronized void last(){
    System.out.println("进入A方法内部");
  }
}